﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using IndicoInterface.SimpleAgendaDataModel;
using DeepTalkWF;
using System.IO;

namespace DeepTalkWFTest
{
    /// <summary>
    /// Summary description for t_RenderMeeting
    /// </summary>
    [TestClass]
    public class t_RenderAllMeetingSlides
    {
        public t_RenderAllMeetingSlides()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void TestBasicRender()
        {
            ///
            /// Create a meeting pointing to a single PDF file
            /// 

            Talk t = Utilities.TalkFromLocalFile("..\\..\\..\\t_DTBuilderLib\\regularPDFfile.pdf");
            Meeting m = Utilities.MeetingFromSingleTalk(t);

            ///
            /// Run the test now
            /// 

            var results = Utilities.RunWFByType(typeof(RenderAllMeetingSlides),
                new Dictionary<string, object>() { { "MeetingInfo", m }, {"DPI", 300} });

            Assert.IsTrue(results != null, "Null result - shoudl be something!");
            Assert.IsTrue(results.ContainsKey("RenderedTalks"), "No rendered talks came back!");
            Assert.IsTrue(results.ContainsKey("NumberOfRenderedTalks"), "No count number of talks came back!");

            Assert.AreEqual(1, (int)results["NumberOfRenderedTalks"], "Expecting only one talk to have been rendered!");

            Dictionary<Talk, List<FileInfo>> flist = results["RenderedTalks"] as Dictionary<Talk, List<FileInfo>>;
            Assert.IsTrue(flist.Count == 1, "Only one talk shoudl be there!");
            Assert.IsTrue(flist.ContainsKey(t), "Does not contain the talk!");
            Assert.IsTrue(flist[t].Count > 0, "No files were rendered for that talk!");
            Assert.IsTrue(flist[t][0].Exists, "First file does not exist!");

            var files = from fl in Directory.GetFiles(".")
                        where fl.Contains("regularPDFfile") && fl.Contains(".jpg")
                        select fl;

            Assert.IsTrue(files.Count() > 0, "No jpeg files found!");
        }
    }
}
